package com.heiketu.init;

import com.heiketu.config.ContextConfig;
import com.heiketu.config.ServletConfig;
import com.heiketu.config.WebSecurityConfig;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.filter.HiddenHttpMethodFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.EnumSet;

public class SimpleAnnotationServletInilizater extends AbstractAnnotationConfigDispatcherServletInitializer {

    /*@Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        // 用于字符编码(UTF-8)
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        FilterRegistration.Dynamic filter1 = servletContext.addFilter("characterEncodingFilter", characterEncodingFilter);
        filter1.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

        // 设置表单形式的restful风格的api提交
        FilterRegistration.Dynamic filter = servletContext.addFilter("hiddenHttpMethodFilter", HiddenHttpMethodFilter.class);
        filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
        super.onStartup(servletContext);
    }*/

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{ContextConfig.class, WebSecurityConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{ServletConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}
